package com.zhike.b2b.admin;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zhike.b2b.info.IInfoService;
import com.zhike.b2b.model.MenuVo;
import com.zhike.b2b.model.UserCore;
import com.zhike.b2b.role.IRoleService;
import com.zhike.b2b.sysparam.IParamService;

@Controller
public class AdminAction {
	
	@Resource
	private IRoleService rs;
	@Resource
	private IParamService ps;
	@Resource
	private IInfoService is;

	@RequestMapping("/admin/getmainview.do")
	public ModelAndView mainView(HttpServletRequest request)
	{
		 ModelAndView mav = new ModelAndView("/admin/mainmenu/home");
		 HttpSession session = request.getSession();
		 UserCore uc = (UserCore)session.getAttribute("OLUSER");
		 int messNum = 0;
		 if(uc!=null)
		 {
			 messNum = is.getMessNum(uc.getUserId());
		 }
		 mav.addObject("messNum",messNum);
		 return mav;
	}
	
	@RequestMapping("/admin/getmessnum.do")
	public ModelAndView messNum()
	{
		 ModelAndView mav = new ModelAndView("/admin/mainmenu/getInfoNum");
		 int comNum = is.getMessNum("company","0");//未审核会员
		 mav.addObject("messNum",comNum);
		 int comAllNum = is.getMessNum("company","all");//会员总数
		 mav.addObject("comAllNum",comAllNum);
		 int authingPros = is.getMessNum("product","0");//未审核产品
		 mav.addObject("authingPros",authingPros);
		 mav.addObject("deletedPros",is.getMessNum("product","9")); //已删除产品
		 mav.addObject("authingSales",is.getMessNum("sales","0"));   //未审核供应
		 mav.addObject("deletedSales",is.getMessNum("sales","9"));  //已删除供应
		 mav.addObject("authingBuys",is.getMessNum("buying","0"));  //未审核求购
		 mav.addObject("deletedBuys",is.getMessNum("buying","9")); //已删除求购
		 mav.addObject("authingNews",is.getMessNum("news","0")); //未审核资讯
		 mav.addObject("allNews",is.getMessNum("news","all")); //资讯总数
		 return mav;
	}
	
	@RequestMapping("/admin/getleftmenus.do")
	public ModelAndView leftMenu(@RequestParam("up_id") String upId)
	{
		 ModelAndView mav = new ModelAndView("/admin/mainmenu/left");
		 String flag = "1111111";
		 if(upId == null|| upId.length()<1)
		 { 
			 upId = "100";
		 }
			
		 List<MenuVo> ml = rs.getAdminMenuList(upId);
		 if(ml!=null&& ml.size()>0)
		 {
			 for(MenuVo mv : ml)
			 {
				 List<MenuVo> secondMls = rs.getAdminMenuList(mv.getMenuId());
				 mv.setSubLms(secondMls);
				 for(MenuVo smv : secondMls)
				 {
					 List<MenuVo> thirdMls = rs.getAdminMenuList(smv.getMenuId());
					 smv.setSubLms(thirdMls);
				 }
			 }
		 }
		 mav.addObject("flag",flag);
		 mav.addObject("menus",ml);
		 return mav;
	}
	
	@RequestMapping("/admin/getadmintop.do")
	public ModelAndView adminTopView(HttpServletRequest request)
	{
		ModelAndView mav = new ModelAndView("/admin/mainmenu/top_operator");
		HttpSession session = request.getSession();
		
		String userType = "",roleId = "" ,name="未登录";
	    UserCore uc = (UserCore)session.getAttribute("OLUSER");
	    List<MenuVo> ml = null;
		if(uc!=null)
		{
			name = uc.getContactName();
			roleId = uc.getRoleAuthId();
			if("0".equals(userType)) {
				ml = rs.getAllMenuInfoByAuthId(roleId);
			}else{
				ml = rs.getAdminMenuList("");
			}
		}
		String adminLogo= ps.getParamValue("admin_logo");
		String companyname= ps.getParamValue("companyname");
		String helpCenter= ps.getParamValue("help_center");
		mav.addObject("menus", ml);
		mav.addObject("name",name);
		mav.addObject("adminLogo",adminLogo);
		mav.addObject("companyname",companyname);
		mav.addObject("hc",helpCenter);
		return mav;
	}
	
	

}
